library(tidyverse)
## -- Attaching packages ------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.2 v purrr 0.3.4
## v tibble 3.0.3 v dplyr 1.0.2
## v tidyr 1.1.2 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ---------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(maps)
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map
library(mapdata)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(viridis)
## Loading required package: viridisLite
library(wesanderson)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
daily_report <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>%
rename(Long = "Long_") %>%
group_by(Country_Region) %>%
summarize(Confirmed = sum(Confirmed), Deaths = sum(Deaths))
## Parsed with column specification:
## cols(
## FIPS = col_double(),
## Admin2 = col_character(),
## Province_State = col_character(),
## Country_Region = col_character(),
## Last_Update = col_datetime(format = ""),
## Lat = col_double(),
## Long_ = col_double(),
## Confirmed = col_double(),
## Deaths = col_double(),
## Recovered = col_double(),
## Active = col_double(),
## Combined_Key = col_character(),
## Incidence_Rate = col_double(),
## `Case-Fatality_Ratio` = col_double()
## )
## `summarise()` ungrouping output (override with `.groups` argument)
world <- as_tibble(map_data("world"))
setdiff(world$region, daily_report$Country_Region)
## [1] "Aruba" "Anguilla"
## [3] "American Samoa" "Antarctica"
## [5] "French Southern and Antarctic Lands" "Antigua"
## [7] "Barbuda" "Saint Barthelemy"
## [9] "Bermuda" "Ivory Coast"
## [11] "Democratic Republic of the Congo" "Republic of Congo"
## [13] "Cook Islands" "Cape Verde"
## [15] "Curacao" "Cayman Islands"
## [17] "Czech Republic" "Canary Islands"
## [19] "Falkland Islands" "Reunion"
## [21] "Mayotte" "French Guiana"
## [23] "Martinique" "Guadeloupe"
## [25] "Faroe Islands" "Micronesia"
## [27] "UK" "Guernsey"
## [29] "Greenland" "Guam"
## [31] "Heard Island" "Isle of Man"
## [33] "Cocos Islands" "Christmas Island"
## [35] "Chagos Archipelago" "Jersey"
## [37] "Siachen Glacier" "Kiribati"
## [39] "Nevis" "Saint Kitts"
## [41] "South Korea" "Saint Martin"
## [43] "Marshall Islands" "Macedonia"
## [45] "Myanmar" "Northern Mariana Islands"
## [47] "Montserrat" "New Caledonia"
## [49] "Norfolk Island" "Niue"
## [51] "Bonaire" "Sint Eustatius"
## [53] "Saba" "Nauru"
## [55] "Pitcairn Islands" "Palau"
## [57] "Puerto Rico" "North Korea"
## [59] "Madeira Islands" "Azores"
## [61] "Palestine" "French Polynesia"
## [63] "South Sandwich Islands" "South Georgia"
## [65] "Saint Helena" "Ascension Island"
## [67] "Solomon Islands" "Saint Pierre and Miquelon"
## [69] "Swaziland" "Sint Maarten"
## [71] "Turks and Caicos Islands" "Turkmenistan"
## [73] "Tonga" "Trinidad"
## [75] "Tobago" "Taiwan"
## [77] "USA" "Vatican"
## [79] "Grenadines" "Saint Vincent"
## [81] "Virgin Islands" "Vanuatu"
## [83] "Wallis and Futuna" "Samoa"
world <- as_tibble(map_data("world")) %>%
mutate(region = str_replace_all(region, c("USA" = "US", "Czech Republic" = "Czechia",
"Ivory Coast" = "Cote d'Ivoire", "Democratic Republic of the Congo" = "Congo (Kinshasa)",
"Republic of Congo" = "Congo (Brazzaville)", "South Korea" = "Korea, South")))
# Join the covid report with the map data
country_join <- left_join(world, daily_report, by = c("region" = "Country_Region"))
# Create the graph
ggplotly(
ggplot(data = world, mapping = aes(x = long, y = lat, text = region, group = group)) +
coord_fixed(1.3) +
geom_polygon(data = country_join, aes(fill = Deaths), color = "black") +
scale_fill_gradientn(colours =
wes_palette("Zissou1", 100, type = "continuous")) +
labs(title = "COVID-19 Deaths")
)
## Warning: `group_by_()` is deprecated as of dplyr 0.7.0.
## Please use `group_by()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
# Create the graph
ggplotly(
ggplot(world, mapping = aes(x = long, y = lat, text = region, size = Confirmed)) +
geom_polygon(data = country_join, aes(fill = Confirmed)) +
scale_fill_gradientn(colours =
wes_palette("Zissou1", 100, type = "continuous")) +
labs(title = "COVID-19 Confirmed")
)
Update Anisa Dhana’s graph layout of the US to 9/26/2020. You may need to adjust the range or change to a linear scale (delete trans=“log”)
daily_report <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>%
rename(Long = "Long_") %>%
filter(Country_Region == "US") %>%
filter (!Province_State %in% c("Alaska","Hawaii", "American Samoa",
"Puerto Rico","Northern Mariana Islands",
"Virgin Islands", "Recovered", "Guam", "Grand Princess",
"District of Columbia", "Diamond Princess")) %>%
filter(Lat > 0)
## Parsed with column specification:
## cols(
## FIPS = col_double(),
## Admin2 = col_character(),
## Province_State = col_character(),
## Country_Region = col_character(),
## Last_Update = col_datetime(format = ""),
## Lat = col_double(),
## Long_ = col_double(),
## Confirmed = col_double(),
## Deaths = col_double(),
## Recovered = col_double(),
## Active = col_double(),
## Combined_Key = col_character(),
## Incidence_Rate = col_double(),
## `Case-Fatality_Ratio` = col_double()
## )
mybreaks <- c(1, 100, 1000, 10000, 100000)
ggplot(daily_report, aes(x = Long, y = Lat, size = Confirmed)) +
borders("state", colour = "white", fill = "grey90") +
geom_point(aes(x=Long, y=Lat, size=Confirmed, color=Confirmed),stroke=F, alpha=0.7) +
scale_size_continuous(name="Cases", range=c(1,7),
breaks=mybreaks, labels = c("1-999",
"1,000-9,999", "10,000-99,999", "100,000-999,999", "500,000+")) +
scale_color_viridis_c(option="viridis",name="Cases",
trans="log", breaks=mybreaks, labels = c("1-999",
"1,000-9,999", "10,000-99,999", "100,000-999,999", "500,000+")) +
theme_void() +
guides( colour = guide_legend()) +
labs(title = "Anisa Dhana's lagout for COVID-19 Confirmed Cases in the US'") +
theme(
legend.position = "bottom",
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA)
) +
coord_fixed(ratio=1.5)
## Warning: Transformation introduced infinite values in discrete y-axis
Update the above graph “Number of Confirmed Cases by US County” to 9/26/2020 and use a different color scheme or theme
library(RColorBrewer)
display.brewer.all()
report_09_26_2020 <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>%
rename(Long = "Long_") %>%
unite(Key, Admin2, Province_State, sep = ".") %>%
group_by(Key) %>%
summarize(Confirmed = sum(Confirmed)) %>%
mutate(Key = tolower(Key))
## Parsed with column specification:
## cols(
## FIPS = col_double(),
## Admin2 = col_character(),
## Province_State = col_character(),
## Country_Region = col_character(),
## Last_Update = col_datetime(format = ""),
## Lat = col_double(),
## Long_ = col_double(),
## Confirmed = col_double(),
## Deaths = col_double(),
## Recovered = col_double(),
## Active = col_double(),
## Combined_Key = col_character(),
## Incidence_Rate = col_double(),
## `Case-Fatality_Ratio` = col_double()
## )
## `summarise()` ungrouping output (override with `.groups` argument)
us <- map_data("state")
counties <- map_data("county")%>%
unite(Key, subregion, region, sep = ".", remove = FALSE)
state_join <- left_join(counties, report_09_26_2020, by = c("Key"))
ggplot(us, aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
borders("state", colour = "black") +
geom_polygon(data = state_join, aes(fill = Confirmed)) +
scale_fill_gradientn(colors = brewer.pal(n = 5, name = "BuPu"),trans = "log10", breaks = c(1, 10, 100, 1000, 10000, 100000), na.value = "White") +
ggtitle("Number of Confirmed Cases by US County") +
theme_bw()
## Warning: Transformation introduced infinite values in discrete y-axis
Make an interactive plot using a state of your chosing using a theme different from used in the above exammples.
daily_report <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>%
rename(Long = "Long_") %>%
filter(Province_State == "Minnesota") %>%
group_by(Admin2) %>%
summarize(Confirmed = sum(Confirmed)) %>%
mutate(Admin2 = tolower(Admin2))
## Parsed with column specification:
## cols(
## FIPS = col_double(),
## Admin2 = col_character(),
## Province_State = col_character(),
## Country_Region = col_character(),
## Last_Update = col_datetime(format = ""),
## Lat = col_double(),
## Long_ = col_double(),
## Confirmed = col_double(),
## Deaths = col_double(),
## Recovered = col_double(),
## Active = col_double(),
## Combined_Key = col_character(),
## Incidence_Rate = col_double(),
## `Case-Fatality_Ratio` = col_double()
## )
## `summarise()` ungrouping output (override with `.groups` argument)
us <- map_data("state")
mn_us <- subset(us, region == "minnesota")
counties <- map_data("county")
mn_county <- subset(counties, region == "minnesota")
state_join <- left_join(mn_county, daily_report, by = c("subregion" = "Admin2"))
library(plotly)
ggplotly(ggplot(data = mn_county, mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
geom_polygon(data = state_join, aes(fill = Confirmed), color = "black") +
scale_fill_gradientn(colors = brewer.pal(n = 5, name = "YlOrRd")) +
ggtitle("COVID-19 Cases in MN") +
labs(x=NULL, y=NULL)+ theme(panel.border = element_blank(), panel.background = element_blank(), axis.ticks = element_blank(), axis.text = element_blank()))
Create a report with static maps and interactive graphs that is meant to be read by others (e.g. your friends and family). Hide warnings, messages and even the code you used so that it is readable. Included references. Link to the Lab 6 report from your Github site. Submit the link to Moodle. Hide warnings, messages and even the code you used so that it is readable. Included references. Link to the Lab 6 report from your Github site. Submit the link to Moodle. I will talk more about the format on Wed.